package com.atguigu.Util;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author hjy
 * @create 2023/3/20 21:04
 */
public class ThreadPoolUtil {
    //使用线程池
    private static ThreadPoolExecutor threadPoolExecutor;

    public static ThreadPoolExecutor getThreadPoolExecutor() {

        if (threadPoolExecutor == null) {
            synchronized (ThreadPoolExecutor.class) {
                if (threadPoolExecutor == null) {
                    threadPoolExecutor = new ThreadPoolExecutor(4, 20, 5, TimeUnit.MINUTES, new LinkedBlockingDeque<>());
                }
            }
        }
        return threadPoolExecutor;
    }
}
